package uk.ac.aber.Blockmation.Actions;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;

import uk.ac.aber.Blockmation.MainFrame;

/**
 * 
 * @author tom, alex
 */

public class ActionDeleteFrame extends AbstractAction {
	
    private MainFrame mainFrame;
    private String path = "../icons/DeleteFrame.gif";

    public ActionDeleteFrame (MainFrame mainFrame) {
        super("Delete Frame");
        this.mainFrame = mainFrame;
        
        // the below from settings class file or?!
        //putValue(SHORT_DESCRIPTION, tooltip);  // Will appear as tooltip text.
        //putValue(MNEMONIC_KEY, new Integer(mnemonic));
        
    }
        
    public void actionPerformed(ActionEvent e) {
        
        int index = mainFrame.getCurrentFrameIndex();
        
        // if index is not first frame, delete it.
        if (index > 0) {
            mainFrame.setCurrentFrameIndex(index-1);
            mainFrame.getMovieModel().removeFrame(index);
            
        // else, clear the frame and append to movieModel
        } else {
            mainFrame.getPad().clear();
            mainFrame.getMovieModel().setFrame(index, mainFrame.getPad().getImage());
        }
        
        mainFrame.updateStatus();
        mainFrame.getCenterBottomPanel().updateImages();
        mainFrame.getCenterBottomPanel().updateCurrentThumb();
    }
    
    public void setImage () {
        CreateImageIcon createImageIcon = new CreateImageIcon();
        putValue(SMALL_ICON, createImageIcon.create(path));
    }

}
